package cn.virens.dd.simple.strategy;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.virens.dd.simple.AbstractStrategy;
import cn.virens.dd.simple.value.StrategyValueByLumen;

/**
 * 光照开灯控制策略（光照值大于配置值）
 * 
 * @author Virens
 */
public class StrategyByLumenOn extends AbstractStrategy<StrategyValueByLumen> {
	private static final int MINUTES_WITH_12 = 12 * 60;

	private final Integer value1; // 12:00 之后控制阀值
	private final Integer value2; // 12:00 之前控制阀值

	public StrategyByLumenOn(Object value1, Object value2) {
		this.value1 = Convert.toInt(value1, Integer.MIN_VALUE);
		this.value2 = Convert.toInt(value2, Integer.MIN_VALUE);
	}

	public Integer getValue1() {
		return value1;
	}

	public Integer getValue2() {
		return value2;
	}

	@Override
	public void close() throws Exception {

	}

	@Override
	protected boolean filter0(StrategyValueByLumen value) {
		if (minutes(DateUtil.date()) > MINUTES_WITH_12) {
			return value.judgeWithWeight(value1);
		} else {
			return value.judgeWithWeight(value2);
		}
	}
}
